import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

class MyQueue {
    private Deque<Integer> stack1;
    private Deque<Integer> stack2;
    public MyQueue() {
        stack1=new LinkedList<>();
        stack2=new LinkedList<>();
    }
    
    public void push(int x) {
        stack1.push(x);
    }
    
    public int pop() {
        if(empty()){
            return -1;
        }
        if(stack2.isEmpty()){
            while(!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }
    
    public int peek() {
        if(empty()){
            return -1;
        }
        if(stack2.isEmpty()){
            while(!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.peek();
    }
    
    public boolean empty() {
        return stack1.isEmpty()&&stack2.isEmpty();
    }
}